jQuery — Ajax Post数据乱码

Categories: JavaScript; Tagged with: ; @ April 20th, 2011 17:47

jQuery.ajax() API:

“POST data will always be transmitted to the server using UTF-8 charset, per the W3C XMLHTTPRequest standard.”  http://api.jquery.com/jQuery.ajax/

使用IE时, 出现乱码… 后台是java, tomcat的server.xml也已配置编码(见:RiaShanghai)….
突然发现用Firefox就木有问题.

“因为jquery ajax是使用utf-8来编码发送数据的,ie在发送时却没加上charset=utf-8,从而导致乱码(IE默认使用iso-8859-1编码)”http://fatkun.com/2010/12/jquery-ajax.html

呃, 应该就是这么个问题了.

解决方法:

$.ajaxSetup({ contentType: "application/x-www-form-urlencoded; charset=utf-8" });

<->



// Proudly powered by Apache, PHP, MySQL, WordPress, Bootstrap, etc,.